import { defineStore } from 'pinia';
import { useStatee } from '@/stores/Stateexample';
import axios from 'axios';

export const useActione = defineStore('Actione', {
    state: () => ({
        count: 0,
        name: 'zzu',
        response: null,  // 定义 response 属性
    }),
    getters: {
        double: state => state.count * 2,
    },
    actions: {
        otherAction() {
            const otherAction = useStatee();
            otherAction.actiontest();
        },
        randomizeCounter() {
            this.count = Math.round(100 * Math.random());
        },
        async testHttpRequest() {
            const url = 'https://httpbin.org/get';
            try {
                const response = await axios.get(url, {
                    headers: {
                        'Content-Type': 'application/json',
                        'Accept': 'application/json',
                    },
                });
                console.log(response.data);
                this.response = response.data;
            } catch (error) {
                console.error('Could not fetch data:', error);
                this.response = null;
            }
        },
    },
});
